<template>
  <div>
    <el-tree
      :data="data"
      :props="defaultProps"
      @node-click="nodeClick"
    >
    </el-tree>
  </div>
</template>

<script>
import PubSub from 'pubsub-js'
export default {
  data() {
    return {
      data: [],
      defaultProps: {
        children: "children",
        label: "name",
      },
    };
  },
  methods: {
    nodeClick(data){
      
      if(data.catLevel==3){
        console.log("被点击的对象为",data)
       // this.$emit("tree-node-click",data);
        //两个参数  第一个发布的事件名称
        //第二个  参数需要发布的值
        PubSub.publish("node-tree-click",data);  //发布
      }
    },
    getTreeList() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/product/category/treelist"),
        method: "get",
        params: this.$http.adornParams(),
      }).then(({ data }) => {
        console.log(data);
        this.data = data.page;
      });
    },
  },
  created() {
    this.getTreeList();
  },
};
</script>
